<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>graphwidget.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-graphicsview-elasticnodes-example.html">Elastic Nodes Example</a></td><td >graphwidget.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">graphwidget.cpp 示例文件</h1>
<span class="subtitle">graphicsview/elasticnodes/graphwidget.cpp</span>
<!-- $$$graphicsview/elasticnodes/graphwidget.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;graphwidget.h&quot;</span>
  <span class="preprocessor">#include &quot;edge.h&quot;</span>
  <span class="preprocessor">#include &quot;node.h&quot;</span>

  <span class="preprocessor">#include &lt;math.h&gt;</span>

  <span class="preprocessor">#include &lt;QKeyEvent&gt;</span>
  <span class="preprocessor">#include &lt;QRandomGenerator&gt;</span>

  GraphWidget<span class="operator">::</span>GraphWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>(parent)<span class="operator">,</span> timerId(<span class="number">0</span>)
  {
      <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>scene <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span>(<span class="keyword">this</span>);
      scene<span class="operator">-</span><span class="operator">&gt;</span>setItemIndexMethod(<span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span><span class="operator">::</span>NoIndex);
      scene<span class="operator">-</span><span class="operator">&gt;</span>setSceneRect(<span class="operator">-</span><span class="number">200</span><span class="operator">,</span> <span class="operator">-</span><span class="number">200</span><span class="operator">,</span> <span class="number">400</span><span class="operator">,</span> <span class="number">400</span>);
      setScene(scene);
      setCacheMode(CacheBackground);
      setViewportUpdateMode(BoundingRectViewportUpdate);
      setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);
      setTransformationAnchor(AnchorUnderMouse);
      scale(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">0.8</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">0.8</span>));
      setMinimumSize(<span class="number">400</span><span class="operator">,</span> <span class="number">400</span>);
      setWindowTitle(tr(<span class="string">&quot;Elastic Nodes&quot;</span>));

      Node <span class="operator">*</span>node1 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node2 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node3 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node4 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      centerNode <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node6 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node7 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node8 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      Node <span class="operator">*</span>node9 <span class="operator">=</span> <span class="keyword">new</span> Node(<span class="keyword">this</span>);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node1);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node2);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node3);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node4);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(centerNode);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node6);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node7);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node8);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(node9);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node1<span class="operator">,</span> node2));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node2<span class="operator">,</span> node3));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node2<span class="operator">,</span> centerNode));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node3<span class="operator">,</span> node6));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node4<span class="operator">,</span> node1));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node4<span class="operator">,</span> centerNode));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(centerNode<span class="operator">,</span> node6));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(centerNode<span class="operator">,</span> node8));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node6<span class="operator">,</span> node9));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node7<span class="operator">,</span> node4));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node8<span class="operator">,</span> node7));
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> Edge(node9<span class="operator">,</span> node8));

      node1<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span><span class="number">50</span><span class="operator">,</span> <span class="operator">-</span><span class="number">50</span>);
      node2<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">0</span><span class="operator">,</span> <span class="operator">-</span><span class="number">50</span>);
      node3<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">50</span><span class="operator">,</span> <span class="operator">-</span><span class="number">50</span>);
      node4<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span><span class="number">50</span><span class="operator">,</span> <span class="number">0</span>);
      centerNode<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      node6<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">50</span><span class="operator">,</span> <span class="number">0</span>);
      node7<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span><span class="number">50</span><span class="operator">,</span> <span class="number">50</span>);
      node8<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">0</span><span class="operator">,</span> <span class="number">50</span>);
      node9<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">50</span><span class="operator">,</span> <span class="number">50</span>);
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>itemMoved()
  {
      <span class="keyword">if</span> (<span class="operator">!</span>timerId)
          timerId <span class="operator">=</span> startTimer(<span class="number">1000</span> <span class="operator">/</span> <span class="number">25</span>);
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>keyPressEvent(<span class="type"><a href="../qtgui/qkeyevent.html">QKeyEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="keyword">switch</span> (event<span class="operator">-</span><span class="operator">&gt;</span>key()) {
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Up:
          centerNode<span class="operator">-</span><span class="operator">&gt;</span>moveBy(<span class="number">0</span><span class="operator">,</span> <span class="operator">-</span><span class="number">20</span>);
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Down:
          centerNode<span class="operator">-</span><span class="operator">&gt;</span>moveBy(<span class="number">0</span><span class="operator">,</span> <span class="number">20</span>);
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Left:
          centerNode<span class="operator">-</span><span class="operator">&gt;</span>moveBy(<span class="operator">-</span><span class="number">20</span><span class="operator">,</span> <span class="number">0</span>);
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Right:
          centerNode<span class="operator">-</span><span class="operator">&gt;</span>moveBy(<span class="number">20</span><span class="operator">,</span> <span class="number">0</span>);
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Plus:
          zoomIn();
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Minus:
          zoomOut();
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Space:
      <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Enter:
          shuffle();
          <span class="keyword">break</span>;
      <span class="keyword">default</span>:
          <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>keyPressEvent(event);
      }
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>timerEvent(<span class="type"><a href="../qtcore/qtimerevent.html">QTimerEvent</a></span> <span class="operator">*</span>event)
  {
      Q_UNUSED(event);

      <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span>Node <span class="operator">*</span><span class="operator">&gt;</span> nodes;
      foreach (<span class="type"><a href="qgraphicsitem.html">QGraphicsItem</a></span> <span class="operator">*</span>item<span class="operator">,</span> scene()<span class="operator">-</span><span class="operator">&gt;</span>items()) {
          <span class="keyword">if</span> (Node <span class="operator">*</span>node <span class="operator">=</span> qgraphicsitem_cast<span class="operator">&lt;</span>Node <span class="operator">*</span><span class="operator">&gt;</span>(item))
              nodes <span class="operator">&lt;</span><span class="operator">&lt;</span> node;
      }

      foreach (Node <span class="operator">*</span>node<span class="operator">,</span> nodes)
          node<span class="operator">-</span><span class="operator">&gt;</span>calculateForces();

      bool itemsMoved <span class="operator">=</span> <span class="keyword">false</span>;
      foreach (Node <span class="operator">*</span>node<span class="operator">,</span> nodes) {
          <span class="keyword">if</span> (node<span class="operator">-</span><span class="operator">&gt;</span>advancePosition())
              itemsMoved <span class="operator">=</span> <span class="keyword">true</span>;
      }

      <span class="keyword">if</span> (<span class="operator">!</span>itemsMoved) {
          killTimer(timerId);
          timerId <span class="operator">=</span> <span class="number">0</span>;
      }
  }

  <span class="preprocessor">#if QT_CONFIG(wheelevent)</span>
  <span class="type">void</span> GraphWidget<span class="operator">::</span>wheelEvent(<span class="type"><a href="../qtgui/qwheelevent.html">QWheelEvent</a></span> <span class="operator">*</span>event)
  {
      scaleView(pow((<span class="type">double</span>)<span class="number">2</span><span class="operator">,</span> <span class="operator">-</span>event<span class="operator">-</span><span class="operator">&gt;</span>delta() <span class="operator">/</span> <span class="number">240.0</span>));
  }
  <span class="preprocessor">#endif</span>

  <span class="type">void</span> GraphWidget<span class="operator">::</span>drawBackground(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> <span class="operator">&amp;</span>rect)
  {
      Q_UNUSED(rect);

      <span class="comment">// Shadow</span>
      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> sceneRect <span class="operator">=</span> <span class="keyword">this</span><span class="operator">-</span><span class="operator">&gt;</span>sceneRect();
      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> rightShadow(sceneRect<span class="operator">.</span>right()<span class="operator">,</span> sceneRect<span class="operator">.</span>top() <span class="operator">+</span> <span class="number">5</span><span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> sceneRect<span class="operator">.</span>height());
      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> bottomShadow(sceneRect<span class="operator">.</span>left() <span class="operator">+</span> <span class="number">5</span><span class="operator">,</span> sceneRect<span class="operator">.</span>bottom()<span class="operator">,</span> sceneRect<span class="operator">.</span>width()<span class="operator">,</span> <span class="number">5</span>);
      <span class="keyword">if</span> (rightShadow<span class="operator">.</span>intersects(rect) <span class="operator">|</span><span class="operator">|</span> rightShadow<span class="operator">.</span>contains(rect))
          painter<span class="operator">-</span><span class="operator">&gt;</span>fillRect(rightShadow<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>darkGray);
      <span class="keyword">if</span> (bottomShadow<span class="operator">.</span>intersects(rect) <span class="operator">|</span><span class="operator">|</span> bottomShadow<span class="operator">.</span>contains(rect))
          painter<span class="operator">-</span><span class="operator">&gt;</span>fillRect(bottomShadow<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>darkGray);

      <span class="comment">// Fill</span>
      <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> gradient(sceneRect<span class="operator">.</span>topLeft()<span class="operator">,</span> sceneRect<span class="operator">.</span>bottomRight());
      gradient<span class="operator">.</span>setColorAt(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);
      gradient<span class="operator">.</span>setColorAt(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>lightGray);
      painter<span class="operator">-</span><span class="operator">&gt;</span>fillRect(rect<span class="operator">.</span>intersected(sceneRect)<span class="operator">,</span> gradient);
      painter<span class="operator">-</span><span class="operator">&gt;</span>setBrush(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoBrush);
      painter<span class="operator">-</span><span class="operator">&gt;</span>drawRect(sceneRect);

      <span class="comment">// Text</span>
      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> textRect(sceneRect<span class="operator">.</span>left() <span class="operator">+</span> <span class="number">4</span><span class="operator">,</span> sceneRect<span class="operator">.</span>top() <span class="operator">+</span> <span class="number">4</span><span class="operator">,</span>
                      sceneRect<span class="operator">.</span>width() <span class="operator">-</span> <span class="number">4</span><span class="operator">,</span> sceneRect<span class="operator">.</span>height() <span class="operator">-</span> <span class="number">4</span>);
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> message(tr(<span class="string">&quot;Click and drag the nodes around, and zoom with the mouse &quot;</span>
                         <span class="string">&quot;wheel or the '+' and '-' keys&quot;</span>));

      <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> font <span class="operator">=</span> painter<span class="operator">-</span><span class="operator">&gt;</span>font();
      font<span class="operator">.</span>setBold(<span class="keyword">true</span>);
      font<span class="operator">.</span>setPointSize(<span class="number">14</span>);
      painter<span class="operator">-</span><span class="operator">&gt;</span>setFont(font);
      painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>lightGray);
      painter<span class="operator">-</span><span class="operator">&gt;</span>drawText(textRect<span class="operator">.</span>translated(<span class="number">2</span><span class="operator">,</span> <span class="number">2</span>)<span class="operator">,</span> message);
      painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>black);
      painter<span class="operator">-</span><span class="operator">&gt;</span>drawText(textRect<span class="operator">,</span> message);
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>scaleView(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> scaleFactor)
  {
      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> factor <span class="operator">=</span> transform()<span class="operator">.</span>scale(scaleFactor<span class="operator">,</span> scaleFactor)<span class="operator">.</span>mapRect(<span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>))<span class="operator">.</span>width();
      <span class="keyword">if</span> (factor <span class="operator">&lt;</span> <span class="number">0.07</span> <span class="operator">|</span><span class="operator">|</span> factor <span class="operator">&gt;</span> <span class="number">100</span>)
          <span class="keyword">return</span>;

      scale(scaleFactor<span class="operator">,</span> scaleFactor);
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>shuffle()
  {
      foreach (<span class="type"><a href="qgraphicsitem.html">QGraphicsItem</a></span> <span class="operator">*</span>item<span class="operator">,</span> scene()<span class="operator">-</span><span class="operator">&gt;</span>items()) {
          <span class="keyword">if</span> (qgraphicsitem_cast<span class="operator">&lt;</span>Node <span class="operator">*</span><span class="operator">&gt;</span>(item))
              item<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span><span class="number">150</span> <span class="operator">+</span> <span class="type"><a href="../qtcore/qrandomgenerator.html">QRandomGenerator</a></span><span class="operator">::</span>global()<span class="operator">-</span><span class="operator">&gt;</span>bounded(<span class="number">300</span>)<span class="operator">,</span> <span class="operator">-</span><span class="number">150</span> <span class="operator">+</span> <span class="type"><a href="../qtcore/qrandomgenerator.html">QRandomGenerator</a></span><span class="operator">::</span>global()<span class="operator">-</span><span class="operator">&gt;</span>bounded(<span class="number">300</span>));
      }
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>zoomIn()
  {
      scaleView(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">1.2</span>));
  }

  <span class="type">void</span> GraphWidget<span class="operator">::</span>zoomOut()
  {
      scaleView(<span class="number">1</span> <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">1.2</span>));
  }

</pre>
</div>
<!-- @@@graphicsview/elasticnodes/graphwidget.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
